package pers.fjl.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.x.protobuf.MysqlxDatatypes;
import org.junit.Test;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import pers.fjl.common.po.Report1;
import pers.fjl.common.vo.Legend;
import pers.fjl.common.vo.Series;
import pers.fjl.test.dao.ReportDao;
import pers.fjl.test.service.ReportService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class ReportServiceImpl extends ServiceImpl<ReportDao, Report1> implements ReportService {
    @Resource
    private ReportDao reportDao;

    public List<Object> findReport() {
        List<Object> list = new ArrayList<Object>();

        List<Report1> s = reportDao.selectList(null);
        for (Report1 report1 : s) {
            Series series = new Series();
            series.setName(report1.getCname());
            series.setData(new int[]{
                    isNUll(report1.getJanuary()),
                    isNUll(report1.getFebruary()),
                    isNUll(report1.getMarch()),
                    isNUll(report1.getApril()),
                    isNUll(report1.getMay()),
                    isNUll(report1.getJune())
            });
            list.add(series);
        }
        return list;
    }

    public Legend getName() {
        QueryWrapper<Report1> wrapper = new QueryWrapper<>();
        List<Report1> s = reportDao.selectList(null);
        Integer integer = reportDao.selectCount(null);
        Legend legend = new Legend();
        List<Report1> list = new ArrayList<>();
        String[] strings = new String[integer];
        int i = 0;
        for (Report1 report1 : s) {
            strings[i] = report1.getCname();
            i++;
        }

        legend.setName(strings);
        return legend;
    }

    public Integer isNUll(String s) {
        if (s == null) {
            return 0;
        }
        return Integer.parseInt(s);
    }

}
